<?
require_once 'config.php';
$pro_id = getValue('iPro','int','GET',0);
$templateProduct = new TemplateProduct();
$pro_info = $templateProduct->pro_detail($pro_id);
$id_field = 'ord_id';
$ord_date = time();
   $myform = new generate_form();
   $myform->add('ord_pro_id','pro_id_order',1,0,'',1,'',0,'');
   $myform->add('ord_pro_number', 'pro_number', 0, 0, '', 1, 'Bạn chưa nhập số lượng.', 0, '');
   $myform->add('ord_cus_phone','phone_contact',0,0,'',1,'Bạn chưa nhập số điện thoại',0);
   $myform->add('ord_cus_name','name_contact',0,0,'',1,'Bạn chưa nhập họ tên',0);
   $myform->add('ord_cus_address','address_contact',0,0,'',0,'',0);
   $myform->add('ord_cus_email', 'email_contact', 0, 0, '', 1, 'Bạn chưa nhập email', 0, '');
   $myform->add('ord_cus_note', 'content_contact', 0, 0, '', 0, '', 0, '');
   $myform->add('ord_date', 'ord_date', 1, 1, 0, 0, '', 0, '');
   $myform->addTable('orders');
   
   
   $action	= getValue('action', 'str', 'POST', '');
   if($action			==	'excute'){
      $pro_id = getValue('pro_id_order','int','POST',0);
      $templateProduct = new TemplateProduct();
      $pro_info = $templateProduct->pro_detail($pro_id);
      $errorMsg_res = '';
      $errorMsg_res		.=	$myform->checkdata();
         if($errorMsg_res == ''){
            $db_ex		=	new db_execute_return();
       			$last_id		=	$db_ex->db_execute($myform->generate_insert_SQL());
       			if($last_id	> 0){   			
       			  send_mailer('anhlam_cnxl@yahoo.com',"Khách hàng đặt mua sản phẩm : ".$pro_info['pro_name'],'Kiểm tra hệ thống để xem khách hàng đặt mua mới nhất',"");
    		         echo "<script>alert('Bạn đã đặt mua thành công !');location.reload();</script>";
               }
    			
         }
   }
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi" lang="vi" xmlns:og="http://ogp.me/ns#" xmlns:fb="">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <link type="image/x-icon" href="/favicon.ico" rel="icon" />
   
   <title>Đặt mua sản phẩm <?=$pro_info['pro_name']?></title>
       <meta property="og:title" content="" />
    <meta property="og:type" content="website" />
    <meta property="og:url" content="" />
    <meta property="og:image" content="" />
    <meta property="og:site_name" content="MassSeo" />
    <meta property="og:description" content="" />
    <meta property="fb:admins" content="100004609203263" />
    <meta property="fb:app_id" content="447585838689244"/> 
    
    <link rel="stylesheet" type="text/css" href="../themes/css/home.css" />	
    <link rel="stylesheet" type="text/css" href="../themes/css/product.css" />
    <link rel="stylesheet" type="text/css" href="../themes/css/order.css" />	
    <!-- css -->
    <link rel="stylesheet" type="text/css" href="../themes/css/bjqs.css" />
    <link rel="stylesheet" type="text/css" href="../themes/css/jquery.fancybox.css" />
    <!-- js -->
	 <script type="text/javascript" src="../themes/js/jquery-1.9.0.min.js"></script>
    <script type="text/javascript" src="../themes/js/bjqs-1.3.min.js"></script>
    <script type="text/javascript" src="../home/js/jquery.fancybox.pack.js"></script>
    <script type="text/javascript" src="../home/js/news.js"></script>
</head>
<body>   
   <div class="wrapper">
      <?
         include('view/common/vic_header.php');
         //include('view/common/vic_breadcrumb.php');
      ?>
   <div class="breadcrumb">
    <span class="crumb_item crumb_item_home">
    	<a  rel="up" class="crumb" href="<?=DOMAIN?>"><span>Trang chủ</span></a>
    	<span class="arrow"><img src="/themes/img/navRow.png" alt="bredcrumb arrow"></span>
    </span>
    <span class="crumb_item">
      <a rel="up" class="crumb" href="<?=generate_product_order_url($pro_info)?>">
            <span>
               Đặt mua sản phẩm : <?=$pro_info['pro_name']?>
            </span>
         </a>
    </span>
            
   </div>
      <div class="primary">
          <div class="sidebar_wrap">
             <? 
               include 'view/common/vic_sidebar.php';
             ?>
          </div>
          <div class="news_line_vertical">&nbsp;</div>
          <div class="content_product">
               <div class="products_hot">
               <form action="" method="POST" onsubmit="return validSend();">
                  <table border="0" cellpadding="7px" cellspacing="4px" width="100%">
                     <tbody>
                        <tr>
                           <td class="tlabel">Lưu ý :</td>
                           <td class="tlabel" style="text-align: left">Bạn vui lòng nhập chính xác thông tin những ô có dấu <span class="imp">*</span></td>
                           
                        </tr>
                        <tr>
                           <td class="tlabel"><span class="imp">*</span>Số lượng</td>
                           <td><input id="pro_number" name="pro_number" class="ctext" type="text" value=""></td>
                        </tr>
                        <tr>
                           <td class="tlabel"><span class="imp">*</span>Họ và tên</td>
                           <td><input id="name_contact" name="name_contact" class="ctext" type="text" value=""></td>
                        </tr>
                        <tr>
                           <td class="tlabel">Địa chỉ</td>
                           <td><input id="address_contact" name="address_contact" class="ctext" type="text" value=""></td>
                        </tr>
                        <tr>
                           <td class="tlabel"><span class="imp">*</span>Điện thoại</td>
                           <td><input id="phone_contact" name="phone_contact" class="ctext" type="text" value=""></td>
                        </tr>
                        <tr>
                           <td class="tlabel"><span class="imp">*</span>Email</td>
                           <td><input id="email_contact" name="email_contact" class="ctext" type="text" value=""></td>
                        </tr>
                        <tr>
                           <td class="tlabel">Ghi chú</td>
                           <td valign="top"><textarea id="content_contact" name="content_contact" class="ctext"></textarea></td>
                        </tr>
                        <tr>
                           <td class="tlabel">&nbsp;</td>
                           <td valign="top">
                              <input type="hidden" class="" name="action" value="excute"/>
                              <input type="hidden" class="" name="pro_id_order" value="<?=$pro_id?>"/>
                              <input type="submit" class="order_submit" name="order_submit" value="Gửi"/>
                              <input type="reset" class="order_reset" name="order_reset" value="Đặt lại"/>
                           </td>
                        </tr>
                     </tbody>
                  </table>
               </form>
         </div><!-- End content -->
   </div><!-- End primary -->
         
         
      <?
         include('view/common/vic_heightlight.php');
         include('view/common/vic_footer.php');
      ?>
   </div>
</body>
</html>
<script>
function isemail(email) {
	var re = /^(\w|[^_]\.[^_]|[\-])+(([^_])(\@){1}([^_]))(([a-z]|[\d]|[_]|[\-])+|([^_]\.[^_])*)+\.[a-z]{2,3}$/i
	return re.test(email);
}
function validSend(){	
   if($('#pro_number').val()==''){
		alert('Hãy nhập số lượng.');
      $('#pro_number').focus();
		return false;
	}
	if($('#name_contact').val()==''){
		alert('Hãy nhập họ và tên.');
		$('#name_contact').focus();
      return false;
	}
	if($('#phone_contact').val()==''){
		alert('Hãy nhập số điện thoại.');
		$('#phone_contact').focus();
      return false;
	}
	if(!isemail($('#email_contact').val())){
		alert('Hãy nhập Email đúng định dạng.');
		$('#email_contact').focus();
      return false;
	}
}
</script>